<%@ taglib uri="/WEB-INF/eam-tag.tld" prefix="eam" %>
<%@ page import="com.sbdcpn.page.utils.RequestUtil,
				 com.sbdcpn.business.wzmis.base.SjTotalBO,
				 java.util.List,
				 java.text.DecimalFormat,
				 java.util.Map" %>
<%/*---设置字符集---*/%>
<eam:PageLanguage />
<%/*---设置字符集---*/%>
<%
	int fontSize = 25;
	DecimalFormat DECIMALFORMAT = new DecimalFormat("0.00");
	String month = RequestUtil.getStringParameter(request ,"month" ,"");
	int ctryType = Integer.parseInt(RequestUtil.getStringParameter(request ,"ctryType" ,"0"));
	String funcid = RequestUtil.getStringParameter(request ,"funcid" ,"");
	boolean isStock = false;
	if ("sjtotal_stock".equals(funcid)){
		isStock = true;
	}

	SjTotalBO sjTotalBO = new SjTotalBO();
	List[] returnList = sjTotalBO.getTotal(month, ctryType, isStock);
	List titleList = returnList[0];
	List contentList = returnList[1];

	int totalWidth = 0;
	int totalCol = 0;
	if (!titleList.isEmpty()){
		totalWidth += 20;
		totalCol += 3;
		List firstList = (List)titleList.get(0);
		List secondList = (List)titleList.get(1);
		for(int i = 0; i < 2; i++){
			String[] col = (String[])firstList.get(i);
			totalWidth += col[0].length() * fontSize;
		}
		totalCol += secondList.size();
		for(int i = 0; i < secondList.size(); i++){
			String[] col = (String[])secondList.get(i);
			totalWidth += col[0].length() * fontSize;
		}
	}
%>
<HTML xmlns:sbdhtc>
<HEAD>
	<TITLE>
<% 		if (isStock){ %>
		<eam:message key="title.sjtotal_stock"/>
<%
		}
		else{
%>
		<eam:message key="title.sjtotal_consume"/>
<%
		}
%>
	</TITLE>
	<link href="<%=CONTEXTPATH%>/css/default.css" rel="stylesheet" type="text/css">
	<script src="<%=CONTEXTPATH%>/utility/class/cutil.js"></script>
	<style>
		sbdhtc\:datagrid{
			behavior: url(<%=CONTEXTPATH%>/utility/component/datagrid.htc) ;
		}
	</style>
</HEAD>
<script language="javascript">
<!--
	function f_forestat() {
		if (check()){
			var formObj = document.forms("frmTotal");
			var month = document.getElementById("month").value;
			var ctryType = document.getElementById("ctryType").value;
			formObj.action="<%=CONTEXTPATH%>/wzmis/stat/sjTotal.jsp?funcid=<%=funcid%>&month="+month+"&ctryType="+ctryType;
			document.getElementById("total").disabled = true;
			document.getElementById("download1").disabled = true;
			formObj.submit();
		}
	}
	function f_forestat2() {
		if (check()){
			var formObj = document.forms("frmTotal");
			var month = document.getElementById("month").value;
			var ctryType = document.getElementById("ctryType").value;
			formObj.action="<%=CONTEXTPATH%>/wzmis/stat/sjTotal2.jsp?funcid=<%=funcid%>&month="+month+"&ctryType="+ctryType;
			formObj.submit();
			return false;
		}
	}
	function check(){
		var isPass = true;
		var ctryTypeObj = document.getElementById("ctryType");
		var monthObj = document.getElementById("month");
		if (!ctryTypeObj.value){
			alert('<eam:message key="sjtotal.err.input"/><eam:message key="sjtotal.ctrltype"/>!');
			isPass = false;
			ctryTypeObj.focus();
		}
		if (!monthObj.value){
			alert('<eam:message key="sjtotal.err.input"/><eam:message key="sjtotal.month"/>!');
			isPass = false;
			monthObj.focus();
		}
		else{
			isPass = checkYearMonth(monthObj);
		}

		return isPass;
	}
	function checkYearMonth(obj) {
		alert("qqqqqqqqqqqqqqqqqqqqqqqqq");
		var value = obj.value;
		var isPass = false;
		if (value){
			var reg = new RegExp("^([1-9]{1}[0-9]{1,3})\-[0-1]{1}[0-9]{1,2}$","g");
			isPass = reg.test(value);
			if (!isPass){
				alert('<eam:message key="common.text.invyearmonth" />');
			}
		}
		if (!isPass && value) obj.focus();
		return isPass;
	}
	function init(){
		var ctryType = <%= ctryType%>;
		document.getElementById("ctryType").value = ctryType;
		document.getElementById("month").focus();
	}
	var curTd = null;
	var selectedColor = "#E1A121";		//已选择颜色
	var unSelectColor = "#e7e7e7";		//未选择颜色
//-->
</script>
<BODY onload="init()">
	<div style="height:20px">
		<form method="post" action="" name="frmtotal" id="frmtotal"></form>
	</div>
	<table width="100%">
		<tr>
<%
	if (totalCol == 0){
%>
			<td bgcolor="#ffffff" align="center">
<%
	}
	else{
%>
			<td colspan=<%= totalCol%> bgcolor="#ffffff" align="center">
<%
	}
%>
				<b>
					<font size="3" font-family="楷体_gb2312" color="black">
<% 					if (isStock){ %>
					<eam:message key="title.sjtotal_stock"/>
<%
					}
					else{
%>
					<eam:message key="title.sjtotal_consume"/>
<%
					}
%>
					</font>
				</b>
			</td>
		</tr>
		<tr>
<%
	if (totalCol == 0){
%>
			<td align="left">
<%
	}
	else{
%>
			<td colspan=<%= totalCol%> align="left">
<%
	}
%>
				<table>
					<tr>
						<td width="70px" align="right"><eam:message key="sjtotal.ctrltype"/>*:&nbsp;</td>
						<td width="50px" align="left">
							<select id="ctryType">
								<option value="0"><eam:message key="ddlb.sjctrltype.0"/></option>
								<option value="1"><eam:message key="ddlb.sjctrltype.1"/></option>
								<option value="2"><eam:message key="ddlb.sjctrltype.2"/></option>
							</select>
						</td>
						<td width="70px" align="right"><eam:message key="sjtotal.month"/>*:&nbsp;</td>
						<td width="40px" align="left"><input type="text" id="month" onblur="checkYearMonth(this)" value="<%= month%>"/></td>
						<td width="50px" align="center"><input type="button" id="total" value='<eam:message key="btn.total2"/>' onclick="f_forestat()"></td>
						<td width="50px" align="center"><input type="button" id="download1" value='<eam:message key="text.total.outexcel"/>' onclick="f_forestat2()" ></td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
<div style=" padding-left: 0px; padding-bottom: 0px; width: 100%; height: 83%; color:#ffffff; margin-top:13px; overflow: auto;">
<!-- sbdhtc:datagrid id="totalgrid" -->
<%
	if (totalWidth == 0){
%>
	<table width="100%" id="tab" class="gridTbl">
<%
	}
	else{
%>
	<table width="<%= totalWidth%>px" id="tab" class="gridTbl">
<%  } %>
		<thead>
<%
	for(int i = 0; i < titleList.size(); i++){
%>
		<tr>
<%		if (i == 0){ %>
			<td width="20px" align="center" rowspan="2" class="gridHead">No.</td>
<%
		}
		List colList = (List)titleList.get(i);
		for(int j = 0; j < colList.size(); j++){
			String[] col = (String[])colList.get(j);
			int width = col[0].length() * fontSize;
			if (i == 0 && j == 1){
%>
			<td colspan="<%= col[1]%>" rowspan="<%= col[2]%>" width="200px" align="center" class="gridHead"><%= col[0]%></td>
<%
			}
			else if (i == 0 && j > 1){
%>
			<td colspan="<%= col[1]%>" rowspan="<%= col[2]%>" align="center" class="gridHead"><%= col[0]%></td>
<%
			}
			else{
%>
			<td colspan="<%= col[1]%>" rowspan="<%= col[2]%>" width="<%= width%>px" align="center" class="gridHead"><%= col[0]%></td>
<%
			}
		}
%>
		</tr>
<%
	}
%>
		</thead>
		<tbody>
<%
	for(int i = 0; i < contentList.size(); i++){
%>
		<tr class="gridData">
<% 		if (i !=  (contentList.size()-1)){ %>
			<td class="gridHead"><%= (i+1)%></td>
<%
		}
		else{
%>
			<td class="gridHead">&nbsp;</td>
<%
		}
		List colList = (List)contentList.get(i);
		for(int j = 0; j < colList.size(); j++){
			String[] col = (String[])colList.get(j);
			if (i !=  (contentList.size()-1) && j < 2){
%>
			<td colspan="<%= col[1]%>" rowspan="<%= col[2]%>" align="left"><%= col[0]%></td>
<%
			}
			else if (i !=  (contentList.size()-1) && j > 1){
%>
			<td colspan="<%= col[1]%>" rowspan="<%= col[2]%>" align="right"><%= col[0]%></td>
<%
			}
			else if (i ==  (contentList.size()-1) && j == 0){
%>
			<td colspan="<%= col[1]%>" rowspan="<%= col[2]%>" align="right"><b><%= col[0]%></b></td>
<%
			}
			else if (i ==  (contentList.size()-1)){
%>
			<td colspan="<%= col[1]%>" rowspan="<%= col[2]%>" align="right"><%= DECIMALFORMAT.format(Double.parseDouble(col[0]))%></td>
<%
			}
		}
%>
		</tr>
<%
	}
%>
		</tbody>
	</table>
</div>
<!-- /sbdhtc:datagrid-->
</BODY>
</HTML>